package com.alks.function.data.vo.finance.lotcost;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alks.common.utils.BigDecimalUtil;
import com.alks.common.utils.excelUtils.nestExcel.convert.DateConvert;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: chen
 * @date: 2024/12/20
 * @description: 指令成本分析详情
 */
@Data
@ApiModel(value = "指令成本分析详情")
public class LotCostAnalysisDetailVO {

    @ApiModelProperty(value = "指令")
    private String lotNo;

    @ApiModelProperty(value = "订单数")
    private String orderQty;

    @ApiModelProperty(value = "补单数")
    private String surplusQty;

    @ApiModelProperty(value = "新/旧款")
    private String styleType;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ApiModelProperty(value = "下单日期")
    @ExcelProperty(converter = DateConvert.class)
    private LocalDateTime orderDate;

    @ApiModelProperty(value = "鞋图")
    private String photoName;

    @ApiModelProperty(value = "客户")
    private String custom;

    @ApiModelProperty(value = "合同号")
    private String customPo;

    @ApiModelProperty(value = "颜色代码")
    private String colorCode;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ApiModelProperty(value = "客人交期")
    @ExcelProperty(converter = DateConvert.class)
    private LocalDateTime deliveryDate;

    @ApiModelProperty(value = "型体/刀模")
    private String style;

    @ApiModelProperty(value = "楦头号")
    private String lastNo;

    @ApiModelProperty(value = "颜色名称")
    private String color;

    @ApiModelProperty(value = "客人货号")
    private String developmentNo;

    @ApiModelProperty(value = "底模")
    private String moldNo;

    @ApiModelProperty(value = "大底厂商")
    private String soleVendor;

    @ApiModelProperty(value = "指令成本")
    private BigDecimal costAmt;

    @ApiModelProperty(value = "面材")
    private BigDecimal upperMtl;

    @ApiModelProperty(value = "面材占比")
    private String upperMtlPer;

    @ApiModelProperty(value = "包材")
    private BigDecimal packMtl;

    @ApiModelProperty(value = "包材占比")
    private String packMtlPer;

    @ApiModelProperty(value = "大底")
    private BigDecimal soleMtl;

    @ApiModelProperty(value = "大底占比")
    private String soleMtlPer;

    @ApiModelProperty(value = "面衬")
    private BigDecimal soleMtl2;

    @ApiModelProperty(value = "面衬占比")
    private String soleMtl2Per;

    @ApiModelProperty(value = "冲裁")
    private BigDecimal cutLabor;

    @ApiModelProperty(value = "冲裁占比")
    private String cutLaborPer;

    @ApiModelProperty(value = "手工")
    private BigDecimal processLabor;

    @ApiModelProperty(value = "手动占比")
    private String processLaborPer;

    @ApiModelProperty(value = "外协")
    private BigDecimal outLabor;

    @ApiModelProperty(value = "外协占比")
    private String outLaborPer;

    @ApiModelProperty(value = "针车")
    private BigDecimal stitchLabor;

    @ApiModelProperty(value = "针车占比")
    private String stitchLaborPer;

    @ApiModelProperty(value = "成型")
    private BigDecimal lastLabor;

    @ApiModelProperty(value = "成型占比")
    private String lastLaborPer;

    @ApiModelProperty(value = "水电")
    private BigDecimal powerFee;

    @ApiModelProperty(value = "水电占比")
    private String powerFeePer;

    @ApiModelProperty(value = "管理")
    private BigDecimal adminFee;

    @ApiModelProperty(value = "管理占比")
    private String adminFeePer;

    @ApiModelProperty(value = "补单")
    private BigDecimal supplementFee2;

    @ApiModelProperty(value = "补单占比")
    private String supplementFee2Per;

    @ApiModelProperty(value = "其他")
    private BigDecimal otherFee;

    @ApiModelProperty(value = "其他占比")
    private String otherFeePer;

    @ApiModelProperty(value = "料")
    private BigDecimal mtl;

    @ApiModelProperty(value = "料占比")
    private String mtlPer;

    @ApiModelProperty(value = "工")
    private BigDecimal labor;

    @ApiModelProperty(value = "工占比")
    private String laborPer;

    @ApiModelProperty(value = "费")
    private BigDecimal fee;

    @ApiModelProperty(value = "费占比")
    private String feePer;

    @ApiModelProperty(value = "面材列表")
    private Items<ReportMtlDetailVO> upperMtlItems;

    @ApiModelProperty(value = "面材多购列表")
    private Items<ReportMtlDetailVO> upperMtlMulItems;

    @ApiModelProperty(value = "大底列表")
    private Items<ReportMtlDetailVO> soleMtlItems;

    @ApiModelProperty(value = "面衬列表")
    private Items<ReportMtlDetailVO> soleMtl2Items;

    @ApiModelProperty(value = "补单费用列表")
    private Items<SupplementDutyVO> supplementDutyItems;

    @ApiModelProperty(value = "其他费用列表")
    private Items<OtherFeeVO> otherFeeItems;

    @Data
    static public class Items<T> {

        public Items(List<T> details, BigDecimal totalAmt, BigDecimal totalAmt2) {
            this.details = details;
            this.totalAmt = totalAmt;
            this.totalAmt2 = totalAmt2;
        }

        @ApiModelProperty(value = "明细")
        private List<T> details;

        @ApiModelProperty(value = "总金额")
        private BigDecimal totalAmt;

        @ApiModelProperty(value = "外协金额")
        private BigDecimal totalAmt2;

        public BigDecimal getTotalAmt() {
            return BigDecimalUtil.numberScale(totalAmt, 2);
        }

        public BigDecimal getTotalAmt2() {
            return BigDecimalUtil.numberScale(totalAmt2, 2);
        }
    }

    public BigDecimal getCostAmt() {
        return BigDecimalUtil.numberScale(
                BigDecimalUtil.sum(this.upperMtl, this.packMtl, this.soleMtl, this.soleMtl2,
                this.cutLabor, this.processLabor, this.outLabor, this.stitchLabor, this.lastLabor,
                this.powerFee, this.adminFee, this.supplementFee2, this.otherFee), 3);
    }

    public String getUpperMtlPer() {
        return BigDecimalUtil.percent(this.upperMtl, getCostAmt(), 0);
    }

    public String getPackMtlPer() {
        return BigDecimalUtil.percent(this.packMtl, getCostAmt(), 0);
    }

    public String getSoleMtlPer() {
        return BigDecimalUtil.percent(this.soleMtl, getCostAmt(), 0);
    }

    public String getSoleMtl2Per() {
        return BigDecimalUtil.percent(this.soleMtl2, getCostAmt(), 0);
    }

    public String getCutLaborPer() {
        return BigDecimalUtil.percent(this.cutLabor, getCostAmt(), 0);
    }

    public String getProcessLaborPer() {
        return BigDecimalUtil.percent(this.processLabor, getCostAmt(), 0);
    }

    public String getOutLaborPer() {
        return BigDecimalUtil.percent(this.outLabor, getCostAmt(), 0);
    }

    public String getStitchLaborPer() {
        return BigDecimalUtil.percent(this.stitchLabor, getCostAmt(), 0);
    }

    public String getLastLaborPer() {
        return BigDecimalUtil.percent(this.lastLabor, getCostAmt(), 0);
    }

    public String getPowerFeePer() {
        return BigDecimalUtil.percent(this.powerFee, getCostAmt(), 0);
    }

    public String getAdminFeePer() {
        return BigDecimalUtil.percent(this.adminFee, getCostAmt(), 0);
    }

    public String getSupplementFee2Per() {
        return BigDecimalUtil.percent(this.supplementFee2, getCostAmt(), 0);
    }

    public String getOtherFeePer() {
        return BigDecimalUtil.percent(this.otherFee, getCostAmt(), 0);
    }

    public BigDecimal getMtl() {
        return BigDecimalUtil.numberScale(
                BigDecimalUtil.sum(this.upperMtl, this.packMtl, this.soleMtl, this.soleMtl2), 3);
    }

    public String getMtlPer() {
        return BigDecimalUtil.percent(getMtl(), getCostAmt(), 0);
    }

    public BigDecimal getLabor() {
        return BigDecimalUtil.numberScale(
                BigDecimalUtil.sum(this.cutLabor, this.processLabor, this.outLabor, this.stitchLabor, this.lastLabor), 3);
    }

    public String getLaborPer() {
        return BigDecimalUtil.percent(getLabor(), getCostAmt(), 0);
    }

    public BigDecimal getFee() {
        return BigDecimalUtil.numberScale(
                BigDecimalUtil.sum(this.powerFee, this.adminFee, this.supplementFee2, this.otherFee), 3);
    }

    public String getFeePer() {
        return BigDecimalUtil.percent(getFee(), getCostAmt(), 0);
    }
}
